﻿using Resto.CostControl.Core.Query.DishModule.QueryObject;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using Resto.CostControl.Core.Query.DishModule.ViewObject;
using Enterprise.Framework.DomainModel.Specifications;
using Enterprise.Framework.DomainModel;
using Resto.CostControl.Core.Facade.DishModule.FacadeObject;
using Enterprise.Framework.Core.Container;
using Resto.CostControl.Core.Facade.DishModule.DataTransferObject;
using System.Collections.Generic;

namespace Resto.CostControl.UnitTest.DishModule
{
    
    
    /// <summary>
    ///这是 DishQOTest 的测试类，旨在
    ///包含所有 DishQOTest 单元测试
    ///</summary>
    [TestClass()]
    public class DishQOTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///获取或设置测试上下文，上下文提供
        ///有关当前测试运行及其功能的信息。
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region 附加测试特性
        // 
        //编写测试时，还可使用以下特性:
        //
        //使用 ClassInitialize 在运行类中的第一个测试前先运行代码
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //使用 ClassCleanup 在运行完类中的所有测试后再运行代码
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //使用 TestInitialize 在运行每个测试前先运行代码
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //使用 TestCleanup 在运行完每个测试后运行代码
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///QueryDishVOByPager 的测试
        ///</summary>
        [TestMethod()]
        public void QueryDishVOByPagerTest()
        {
            DishFO target1 = ObjectCreator.Create<DishFO>();

            for (int i = 30; i < 50; i++)
            {
                DishDTO dishDTO = new DishDTO()
                {
                    Category = "a",
                    Code = i.ToString(),
                    CookType = "b",
                    Cost = 11m,
                    Name = i.ToString(),
                    Price = 2m,
                };

                DishMaterialDTO item1 = new DishMaterialDTO(1);
                DishMaterialDTO item2 = new DishMaterialDTO(2);

                List<DishMaterialDTO> list = new List<DishMaterialDTO>();
                list.Add(item1);
                list.Add(item2);

                target1.AddDish(dishDTO, list);
            }
            
            DishQO target = ObjectCreator.Create<DishQO>(); ; // TODO: 初始化为适当的值
            ISpecification<DishVO> spec = Specification<DishVO>.Create(p => p.ID > 0);
            PagerCondition pager = new PagerCondition()
            {
                CurrentPage = 2,
                PageSize = 10,
            };

            string orderKey = "Name";
            bool isAscending = true; ;

            DishVO[] actual;
            actual = target.QueryDishVOByPager(spec, pager, orderKey, isAscending);
            Assert.AreEqual(10, actual.Length);
          }
    }
}
